package com.ling.service;

import com.ling.bean.Report;
import com.ling.bean.ReportExample;
import com.ling.dao.ReportMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReportService {
    private final ReportMapper reportMapper;

    @Autowired
    public ReportService(ReportMapper reportMapper) {
        this.reportMapper = reportMapper;
    }

    //保存
    public void saveReport(Report report) {
        reportMapper.insertSelective(report);
    }

    //判断记录是否存在
    public boolean existReport(Report report) {
        ReportExample reportExample = new ReportExample();
        reportExample.createCriteria().andUseridEqualTo(report.getUserid()).andReporttypeEqualTo(report.getReporttype()).andReportfieldidEqualTo(report.getReportfieldid()).andHasreadEqualTo(0);
        return reportMapper.countByExample(reportExample)>0;
    }

    //查询博客举报
    public List<Report> getReportWithBlog() {
        return reportMapper.getReportWithBlog();
    }

    //查询问题举报
    public List<Report> getReportWithQuestion() {
        return reportMapper.getReportWithQuestion();
    }

    //查询回答举报
    public List<Report> getReportWithAnswer() {
        return reportMapper.getReportWithAnswer();
    }

    //已读操作
    public void read(String reportId) {
        Report report = new Report();
        report.setId(reportId);
        report.setHasread(1);
        reportMapper.updateByPrimaryKeySelective(report);
    }
}
